import React, { memo, lazy, Suspense, useEffect, useState, createContext } from 'react';
import Header from "@/components/header"
import Chat from '@/components/chat/chatIndex'
import { Route, Switch } from 'react-router-dom'
import { Spin, BackTop } from 'antd'
import '../../index.css'
import { getUserInfo } from '@/api/user'
import { StudentInfo } from '../../utils/model';
const classIndex = lazy(() => import('./classIndex')) //工作台
const myCenter = lazy(() => import('./myCenter')) //个人中心

const schoolIndex = lazy(() => import('../schoolCircle/schoolIndex')) //校园圈
const thingLost = lazy(() => import('../schoolCircle/thingLost')) //失物招领
const lostThingDetail = lazy(() => import('../schoolCircle/lostThingDetail')) //失物详情
const confession = lazy(() => import('../schoolCircle/confession')) //表白墙
const secondHand = lazy(() => import('../schoolCircle/SecondhandTransfer')) //二手交易

const homework = lazy(() => import('./homework')) //我的作业
const handlehomework = lazy(()=> import('./handleWork')) //提交作业
const studyIndex = lazy(()=> import('./studyIndex')) //青年大学习
const setting = lazy(() => import('../setting/setting')) //个人设置

export default memo(function Home() {
  const [studentInfo, setStudentInfo] = useState(null)   //用户信息
  const [newMessageCount,setnewMessageCount] = useState(0)
  const getStudentInfo = () =>{
    getUserInfo().then(res => {
      res.data.data[0].classInfo = res.data.classInfo
      setStudentInfo(res.data.data[0])
    })
  }
  useEffect(() => {
    getStudentInfo()
  }, [])

  
  return <Suspense fallback={
    <Spin tip="Loading...">
      <div style={{ height: 500 }}></div>
    </Spin>
  }>
    <div style={{ height: '100vh' }}>
      <Header setnewMessageCount={setnewMessageCount} newMessageCount={newMessageCount}/>
      <div className='fixed-back'
        style={{
          background: 'url("https://www.donglongdong.xyz/images/upload/allback.png") no-repeat',
          // backgroundRepeat: 'no-repeat',
          backgroundSize: 'cover',
          zIndex: '-1'
        }}
      ></div>
      <Chat setnewMessageCount={setnewMessageCount} newMessageCount={newMessageCount}/>
      <div>
        <BackTop />
      </div>
      <div style={{ paddingTop: '64px' }}></div>
      {studentInfo && <StudentInfo.Provider value={{studentInfo: studentInfo,getStudentInfo: getStudentInfo}}>
        <Switch>
          <Route exact path="/home/classIndex" component={classIndex} />
          <Route exact path="/home/class/homework" component={homework} />
          <Route exact path="/home/class/homework/handleWork" component={handlehomework} />
          <Route exact path="/home/myCenter" component={myCenter}/>
          <Route exact path="/home/myCenter/setMyInfo" component={myCenter}/>
          <Route exact path="/home/myCenter/myEmail" component={myCenter} />
          <Route exact path="/home/myCenter/emailDetail" component={myCenter} />
          <Route exact path="/home/myCenter/classInfo" component={myCenter}/>
          <Route exact path="/home/schoolIndex" component={schoolIndex} />
          <Route exact path="/home/schoolIndex/confession" component={confession} />
          <Route exact path="/home/schoolIndex/confession/confessionCards" component={confession} />
          <Route exact path="/home/schoolIndex/confession/createConfession" component={confession} />
          <Route exact path="/home/schoolIndex/confession/confessionDetail" component={confession} />
          <Route exact path="/home/schoolIndex/secondHand" component={secondHand} />
          <Route exact path="/home/schoolIndex/thingLost" component={thingLost} />
          <Route exact path="/home/schoolIndex/thingLostDetail" component={lostThingDetail} />
          <Route exact path="/home/class/studyInfo" component={studyIndex} />
          <Route exact path="/home/setting" component={setting} />
          <Route exact path="/home/setting/permission" component={setting} />
          <Route exact path="/home/setting/personnalSet" component={setting} />
          <Route exact path="/home/setting/permission/classPermission" component={setting} />
          <Route exact path="/home/setting/permission/schoolPermission" component={setting} />
          <Route exact path="/home/setting/personalization" component={setting} />
          <Route exact path="/home/setting/pictureMonitor" component={setting} />
          <Route exact path="/home/setting/prizeBackStage" component={setting} />
          <Route exact path="/home/setting/classManage" component={setting} />
        </Switch>
      </StudentInfo.Provider>}
    </div>
  </Suspense>
});
